<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="请输入年度搜索" prop="duringYear">
        <el-input
          v-model="queryParams.creditLabel"
          placeholder="请输入年度搜索"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['county:credit:export']"
        >导出</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column width="120" label="年度" align="center" prop="duringYear" fixed="left" />
      <el-table-column label="借款人信息(学生)" align="center" >
        <el-table-column width="120" label="QQ" align="center" prop="qq" />
        <el-table-column width="180" label="学生身份证" align="center" prop="cardIdentity" />
        <el-table-column width="120" label="户口性质" align="center" prop="residence" />
        <el-table-column width="120" label="毕业中学" align="center" prop="medium" :show-overflow-tooltip="true" />
        <el-table-column width="120" label="户籍" align="center" prop="household" :show-overflow-tooltip="true" />
        <el-table-column width="120" label="申贷原因" align="center" prop="applyReason" :show-overflow-tooltip="true" />
        <el-table-column width="180" label="学生身份证有效起始日期" align="center" prop="studentEffectiveCardIdentity">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.studentEffectiveCardIdentity) }}</span>
          </template>
        </el-table-column>
        <el-table-column width="180" label="学生身份证有效结束日期" align="center" prop="studentInvalidCardIdentity" >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.studentInvalidCardIdentity) }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column width="120" label="共同借款人" align="center" :show-overflow-tooltip="true" >
        <el-table-column width="120" label="共同借款人姓名" align="center" prop="guarantor" :show-overflow-tooltip="true" />
        <el-table-column width="180" label="共同借款人联系电话" align="center" prop="guaPhone" :show-overflow-tooltip="true" />
        <el-table-column width="120" label="关系" align="center" prop="relation" :show-overflow-tooltip="true" />
        <el-table-column width="180" label="共同借款人身份证号" align="center" prop="guaCardIdentity" :show-overflow-tooltip="true" />
        <el-table-column width="120" label="健康状态" align="center" prop="heath" :show-overflow-tooltip="true" />
      </el-table-column>
      <el-table-column width="240" label="资助中心" align="center" >
        <template slot-scope="scope">
          <span>{{ scope.row.supportCenterProvince }} {{ scope.row.supportCenterCity }} {{ scope.row.supportCenterArea }}</span>
        </template>
      </el-table-column>
      <el-table-column width="240" label="入学前户籍所在地" align="center" >
        <template slot-scope="scope">
          <span>{{ scope.row.householdOfProvince }} {{ scope.row.householdOfCity }} {{ scope.row.householdOfArea }} {{ scope.row.householdOfCounty }} {{ scope.row.householdOfDetail }}</span>
        </template>
      </el-table-column>
      <el-table-column label="家庭住址" align="center" :show-overflow-tooltip="true" >
        <el-table-column width="240" label="家庭住址所在地" align="center" >
          <template slot-scope="scope">
            <span>{{ scope.row.homeOfProvince }} {{ scope.row.homeOfCity }} {{ scope.row.homeOfArea }} {{ scope.row.homeOfCounty }} {{ scope.row.homeOfDetail }}</span>
          </template>
        </el-table-column>
        <el-table-column width="140" label="是否与户籍地址一致" align="center" prop="isTheSameAsHousehold" :show-overflow-tooltip="true" >
          <template slot-scope="scope">
            <span>{{ scope.row.isTheSameAsHousehold === 'true' ? '是' : '否'  }}</span>
          </template>
        </el-table-column>
        <el-table-column width="140" label="家庭住址邮政编码" align="center" prop="homeOfPostcode" :show-overflow-tooltip="true" />
        <el-table-column width="120" label="家庭电话" align="center" prop="homeOfPhone" :show-overflow-tooltip="true" />
      </el-table-column>
      <el-table-column label="就学信息" align="center" :show-overflow-tooltip="true" >
        <el-table-column label="高校名称" align="center" prop="collegeOfName" :show-overflow-tooltip="true" />
        <el-table-column width="160" label="院系名称" align="center" prop="collegeOfInstitute" :show-overflow-tooltip="true" />
        <el-table-column label="专业名称" align="center" prop="collegeOfMajor" :show-overflow-tooltip="true" />
        <el-table-column label="入学时间" align="center" prop="collegeWithStart" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.collegeWithStart) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="学历" align="center" prop="collegeOfEducation" :show-overflow-tooltip="true" />
        <el-table-column width="120" label="学生学号" align="center" prop="studentNo" :show-overflow-tooltip="true" />
        <el-table-column label="专业类别" align="center" prop="typeOfMajor" :show-overflow-tooltip="true" />
        <el-table-column label="学制" align="center" prop="collegeOfEducationalSystem" :show-overflow-tooltip="true" />
        <el-table-column label="毕业时间" align="center" prop="collegeWithEnd" width="120" />
      </el-table-column>
      <el-table-column width="120" label="资格审查确认" align="center" :show-overflow-tooltip="true" >
        <el-table-column width="120" label="资格审查单位" align="center" prop="countyUnit" :show-overflow-tooltip="true" />
        <el-table-column width="120" label="是否盖章" align="center" prop="isSeal" :show-overflow-tooltip="true" />
        <el-table-column width="120" label="盖章日期" align="center" prop="sealDate" :show-overflow-tooltip="true" />
        <el-table-column width="120" label="学生签字日期" align="center" prop="signatureDate"/>
      </el-table-column>
      <el-table-column label="就业信息" align="center" :show-overflow-tooltip="true" >
        <el-table-column label="工作单位" align="center" prop="workFeature" :show-overflow-tooltip="true" />
        <el-table-column label="单位性质" align="center" prop="phoneOfUnit" :show-overflow-tooltip="true" />
        <el-table-column label="单位电话" align="center" prop="postCodeOfUnit" :show-overflow-tooltip="true" />
        <el-table-column width="140" label="单位邮政编码" align="center" prop="addressOfUnit" :show-overflow-tooltip="true" />
        <el-table-column label="单位地址" align="center" prop="addressOfUnit" :show-overflow-tooltip="true" />
      </el-table-column>
      <el-table-column label="变更" align="center" prop="changeForReason" :show-overflow-tooltip="true" />
      <el-table-column width="100" label="是否已签章" align="center" prop="isSeal" :show-overflow-tooltip="true" />
      <el-table-column label="双方签订合同状态" fixed="right" width="200" align="center" :show-overflow-tooltip="true" >
        <el-table-column label="借款人" width="100" align="center" prop="firstSignature" :show-overflow-tooltip="true" >
          <template slot-scope="scope">
            {{ scope.row.firstSignature ? '已签' : '未签' }}
          </template>
        </el-table-column>
        <el-table-column label="县资助中心" width="100" align="center" prop="secondSignature" :show-overflow-tooltip="true" >
          <template slot-scope="scope">
            {{ scope.row.secondSignature ? '已签' : '未签' }}
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="县资助中心审批状态" prop="creditStatus" align="center" fixed="right" width="140" class-name="small-padding fixed-width" />
      <el-table-column label="银行审批状态" prop="isBankCheck" align="center" fixed="right" width="140" class-name="small-padding fixed-width" >
        <template slot-scope="scope">
          {{ scope.row.isBankCheck ? '已审批通过' : '未经过审批' }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" width="140" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.isBankCheck === '已审批'"
            size="small"
            type="success"
            icon="el-icon-edit"
            :disabled="scope.row.isIssue === '已发放' ? true : false"
            @click="handleUpdate(scope.row)"
          >{{ scope.row.isIssue === '已发放' ? '已发放' : '发放贷款' }}</el-button>
          <el-button
            v-if="scope.row.isBankCheck !== '已审批'"
            size="small"
            type="warning"
            icon="el-icon-edit"
          >请先审批</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog title="确认发放贷款金额" :visible.sync="open">
      <el-form>
        <el-form-item label="本次发放金额(学生的贷款金额)" >
          <el-tag type="success" effect="dark">{{ firstBorrowMoney }} 元</el-tag>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>

  import { listData, getData, delData, updateData, exportData } from "@/api/county/credit";
  import { listUser, getUser } from "@/api/system/user";
  import { regionData,CodeToText } from 'element-china-area-data'
  import {addData, newOne} from "../../../../api/hsien/contract";
  import { getCredits, updateCheckStatus } from '../../../../api/county/credit'
  import { sendSms } from '../../../../api/dysms/dysms'

  export default {
    name: "Data",
    data() {
      return {
        firstBorrowMoney: '',
        firstSignaturePath: '',
        secondSignaturePath: '',
        now_creditId: '',
        innerVisible: false,
        openDetail: false,
        contract: {
          contractId: undefined,
          firstName: undefined,
          firstAddress: '广西桂林',
          firstPostCode: '547103',
          firstIdentity: '452724199807151615',
          firstEmail: '582532183@qq.com',
          firstPhone: '13617786374',
          secondName: '王志',
          secondAddress: '广西桂林',
          secondPostCode: '432000',
          secondAgentMan: '李焕',
          secondEmail: 'lh@163.com',
          secondPhone: '18116741246',
          agentEmail: 'agent@163.com',
          agentPhone: '13618899906',
          firstBorrowMoney: '6000',
          borrowYear: '2',
          startYear: '2020',
          startMonth: '10',
          startDay: '14',
          toYear: '2024',
          toMonth: '10',
          toDay: '14',
          monthRate: '60%',
          hasCondition: '无',
          accountName: 'tlg1768llssjdz',
          accountNo: '123456',
          inYear: '2',
          upYear: '3',
          excludeYear: '2',
          countDay: '4',
          borrowLimitYear: '2',
          borrowInYear: '2',
          preDay: '4',
          mustDay: '4',
          expireDay: '4',
          otherCondition: '无',
          lawName: '银行财政',
          commissionName: '贷款金融',
          commissionAddress: '广西南宁',
          concatNum: '2',
          firstSignature: undefined,
          secondSignature: undefined,
          secondElectronic: undefined,
          agentNameSignature: undefined,
          didYear: '2020',
          didMonth: '10',
          didDay: '14',
          condition: '无',
        },
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 学生贷款表格数据
        dataList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 状态数据学生贷款
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          duringYear: undefined,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        },
      };
    },
    created() {
      const userId = this.$route.params && this.$route.params.userId;
      this.getUser(userId);
      this.getUserList();
      getCredits("谭卢钢").then( res => {
        console.log(res)
      });
    },
    methods: {
      getUser(userId) {
        getUser(userId).then(response => {
          this.queryParams.userName = response.data.userName;
          this.getList();
        });
      },
      /** 查询学生贷款列表 */
      getUserList() {
        listUser().then(response => {
        });
      },
      /** 查询学生贷款数据列表 */
      getList() {
        this.loading = true;
        listData(this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.openDetail = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          creditId: undefined,
          duringYear: undefined,
          qq: undefined,
          birth: undefined,
          cardIdentity: undefined,
          residence: undefined,
          medium: undefined, household: undefined,
          email: undefined, address: undefined, postcode: undefined,
          guarantor: undefined, guaPhone: undefined, relation: undefined,
          guaCardIdentity: undefined, heath: undefined,
          applyReason: undefined, signatureDate: undefined, countryUnit: undefined,
          isSeal: undefined, sealDate: undefined, studentEffectiveCardIdentity: undefined,
          studentInvalidCardIdentity: undefined, supportCenterProvince: undefined,
          supportCenterCity: undefined, supportCenterArea: undefined,
          householdOfProvince: undefined, householdOfCity: undefined,
          householdOfArea: undefined, householdOfCounty: undefined,
          householdOfDetail: undefined, homeOfProvince: undefined,
          homeOfCity: undefined, homeOfArea: undefined, homeOfCounty: undefined,
          homeOfDetail: undefined, isTheSameAsHousehold: undefined,
          homeOfPostcode: undefined, homeOfPhone: undefined, concatOfName: undefined,
          concatWorkUnit: undefined, concatOfPhone: undefined, concatOfCardIdentity: undefined,
          collegeOfName: undefined, collegeOfInstitute: undefined,
          collegeOfMajor: undefined, collegeOfEducation: undefined,
          collegeWithStart: undefined, studentNo: undefined, typeOfMajor: undefined,
          collegeOfEducationalSystem: undefined,
          collegeWithEnd: undefined, workUnit: undefined, workFeature: undefined,
          phoneOfUnit: undefined, postcodeOfUnit: undefined, addressOfUnit: undefined,
          changeForReason: undefined, isContractSign: undefined, firstSignature: undefined, secondSignature: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.creditId)
        this.single = selection.length!=1
        this.multiple = !selection.length
      },
      /** 提交按钮 */
      submitForm: function() {
        this.form.isIssue = '已发放'
        updateData(this.form).then(() => {
          this.msgSuccess('本此贷款发放成功!')
          this.getList()
          this.open = false
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportData(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
      },
      // 贷款审核状态修改
      handleUpdate(row) {
        this.form = row
        this.firstBorrowMoney = row.contract.firstBorrowMoney
        this.reset();
        this.open = true
        const creditId = row.creditId || this.ids
        getData(creditId).then(response => {
          this.form = response.data;
        })
      },
    },
  };
</script>

<style>

  input {
    width: 220px;
    border-top-width: 0px;
    border-left-width: 0px;
    border-right-width: 0px;
    border-bottom-width: 1px;
    outline:none;
  }
</style>
